import Mock from 'mockjs'

const userList = [{
  user: 'admin',
  pwd: 'admin'
},{
  user: '123',
  pwd: '123'
}]


const data = Mock.mock({
  "list|10-20": [{
    "url": '@image(100x100, @color)',
    "title": "@ctitle",
    "desc": '@cparagraph(2,4)',
    "id": '@id'
  }]
})

Mock.mock('/api/login', 'post', (req) => {
  const { user, pwd } = JSON.parse(req.body)

  const isExist = userList.find(item => user === item.user && pwd === item.pwd)


  if(isExist) {
    return {
      code: 200,
      token: user
    }
  } else {
    return {
      code: 401,
    }
  }
})

Mock.mock('/api/list', () => {
  return {
    code: 200,
    data: data.list
  }
})